package com.liyao.wftwnetdesk.Utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @program: windowtest4
 * @description:
 * @author: liu yan
 * @create: 2024-11-01 11:27
 */
public class getWiFiName {

    public static String getWiFiName() {
        String wifiName = null;
        try {
//            Process process = Runtime.getRuntime().exec("networksetup -getairportnetwork en0");
            Process process = Runtime.getRuntime().exec("netsh wlan show interfaces"); //windows
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println("line"+line);
                if (line.contains("SSID")) {
                    wifiName = line.split(":")[1].trim();
                    break;
                }
            }
            process.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(wifiName == null){
            wifiName="未获取";
        }
        return wifiName;
    }
}
